﻿namespace WMS6.Web.Analytics
{
    using System;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.AnalyticsReportServiceRef;
    using WMS6.Web.UserControls;

    public class OnTheWayOrderRptList : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnRefresh;
        protected Button btnReSearch;
        protected Button btnSearch;
        protected HtmlForm F15361;
        protected GridView gvOnTheWayOrderRpt;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdnFrom;
        protected HtmlHead Head1;
        protected Label lblMsg;
        protected Label lblOnTheWayOrderRptList;
        protected Label lblTotal;
        protected Label lblTotalCube;
        protected Label lblTotalCubeText;
        protected Label lblTotalExtendedPrice;
        protected Label lblTotalExtendedPriceText;
        protected Label lblTotalGrossWgt;
        protected Label lblTotalGrossWgtText;
        protected Label lblTotalPrice;
        protected Label lblTotalPriceText;
        protected Label lblTotalQtyText;
        protected HtmlLink mycss;
        protected Pager PagerFooter;
        protected ScriptManager ScriptManager1;
        private decimal TotalCube;
        private decimal TotalExtendedPrice;
        private decimal TotalGrossWgt;
        private decimal TotalPrice;
        private decimal TotalQty;
        protected UpdatePanel up1;

        public void BindData2gvInOutStockList(OnTheWayOrderRptQueryEntity onTheWayOrderRptQueryEntity)
        {
            this.PagerFooter.CurrentPage = int.Parse(onTheWayOrderRptQueryEntity.CurrentPage);
            DataSet ds = AnalyticsReportServiceClientProxy.GetInstance().GetOnTheWayOrderRptDataSet(onTheWayOrderRptQueryEntity);
            base.BindData2GridView(this.gvOnTheWayOrderRpt, ds);
            if ((ds != null) && (ds.Tables.Count > 1))
            {
                this.PagerFooter.PageInfo = ds.Tables[1].Rows[0]["CurrentPage"].ToString() + " / " + ds.Tables[1].Rows[0]["TotalPagesCount"].ToString() + "&nbsp;&nbsp;&nbsp;共: " + ds.Tables[1].Rows[0]["TotalRecordsCount"].ToString();
                this.PagerFooter.TotalPages = int.Parse(ds.Tables[1].Rows[0]["TotalPagesCount"].ToString());
            }
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            OnTheWayOrderRptQueryEntity onTheWayOrderRptQueryEntity = this.GetOnTheWayOrderRptQueryEntity();
            onTheWayOrderRptQueryEntity.IsGetAll = true;
            this.hdnActionID.Value = "EXPORT";
            string currentPageIndex = onTheWayOrderRptQueryEntity.CurrentPage;
            onTheWayOrderRptQueryEntity.CurrentPage = "0";
            this.gvOnTheWayOrderRpt.Columns[1].Visible = false;
            this.gvOnTheWayOrderRpt.AllowSorting = false;
            this.gvOnTheWayOrderRpt.ShowFooter = false;
            this.BindData2gvInOutStockList(onTheWayOrderRptQueryEntity);
            onTheWayOrderRptQueryEntity.IsGetAll = false;
            onTheWayOrderRptQueryEntity.CurrentPage = currentPageIndex;
            this.SetOnTheWayOrderRptQueryEntity(onTheWayOrderRptQueryEntity);
            base.Export2Excel("OnTheWayOrderRpt.xls", this.gvOnTheWayOrderRpt);
        }

        protected void btnFirst_Click(object sender, EventArgs e)
        {
            OnTheWayOrderRptQueryEntity onTheWayOrderRptQueryEntity = this.GetOnTheWayOrderRptQueryEntity();
            onTheWayOrderRptQueryEntity.CurrentPage = "0";
            this.BindData2gvInOutStockList(onTheWayOrderRptQueryEntity);
        }

        protected void btnLast_Click(object sender, EventArgs e)
        {
            OnTheWayOrderRptQueryEntity onTheWayOrderRptQueryEntity = this.GetOnTheWayOrderRptQueryEntity();
            onTheWayOrderRptQueryEntity.CurrentPage = (this.PagerFooter.TotalPages - 1).ToString();
            this.BindData2gvInOutStockList(onTheWayOrderRptQueryEntity);
        }

        protected void btnList_Click(object sender, EventArgs e)
        {
            OnTheWayOrderRptQueryEntity onTheWayOrderRptQueryEntity = this.GetOnTheWayOrderRptQueryEntity();
            onTheWayOrderRptQueryEntity.PO_ID = "";
            onTheWayOrderRptQueryEntity.PO_DATE = "";
            onTheWayOrderRptQueryEntity.EXTERNAL_PO_ID = "";
            onTheWayOrderRptQueryEntity.OWNER_ID = "";
            onTheWayOrderRptQueryEntity.VENDOR_ID = "";
            onTheWayOrderRptQueryEntity.SKU_CLASS_ID = "";
            onTheWayOrderRptQueryEntity.SKU_ID = "";
            onTheWayOrderRptQueryEntity.PO_DATE = "";
            this.BindData2gvInOutStockList(onTheWayOrderRptQueryEntity);
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            OnTheWayOrderRptQueryEntity onTheWayOrderRptQueryEntity = this.GetOnTheWayOrderRptQueryEntity();
            if (int.Parse(onTheWayOrderRptQueryEntity.CurrentPage) < (this.PagerFooter.TotalPages - 1))
            {
                onTheWayOrderRptQueryEntity.CurrentPage = (int.Parse(onTheWayOrderRptQueryEntity.CurrentPage) + 1).ToString();
                this.BindData2gvInOutStockList(onTheWayOrderRptQueryEntity);
            }
        }

        protected void btnPrevious_Click(object sender, EventArgs e)
        {
            OnTheWayOrderRptQueryEntity onTheWayOrderRptQueryEntity = this.GetOnTheWayOrderRptQueryEntity();
            if (int.Parse(onTheWayOrderRptQueryEntity.CurrentPage) > 0)
            {
                onTheWayOrderRptQueryEntity.CurrentPage = (int.Parse(onTheWayOrderRptQueryEntity.CurrentPage) - 1).ToString();
                this.BindData2gvInOutStockList(onTheWayOrderRptQueryEntity);
            }
        }

        protected void btnRefresh_Click(object sender, EventArgs e)
        {
            OnTheWayOrderRptQueryEntity onTheWayOrderRptQueryEntity = this.GetOnTheWayOrderRptQueryEntity();
            this.BindData2gvInOutStockList(onTheWayOrderRptQueryEntity);
        }

        private OnTheWayOrderRptQueryEntity GetOnTheWayOrderRptQueryEntity()
        {
            return (base.PageQueryEntitySession as OnTheWayOrderRptQueryEntity);
        }

        protected void GoTo_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(((TextBox) this.PagerFooter.FindControl("txtGo2Page")).Text.Trim()))
            {
                OnTheWayOrderRptQueryEntity onTheWayOrderRptQueryEntity = this.GetOnTheWayOrderRptQueryEntity();
                onTheWayOrderRptQueryEntity.CurrentPage = this.PagerFooter.GoToPage.ToString();
                this.BindData2gvInOutStockList(onTheWayOrderRptQueryEntity);
            }
        }

        protected void gvOnTheWayOrderRpt_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F15351", this.gvOnTheWayOrderRpt);
        }

        protected void gvOnTheWayOrderRpt_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (((this.PagerFooter.CurrentPage * this.PagerFooter.PageSize) + e.Row.RowIndex) + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                e.Row.Attributes.Add("ondblclick", "JavaScript:document.getElementById('" + ((CheckBox) e.Row.FindControl("chbSelect")).ClientID + "').click();");
                if (this.hdnActionID.Value != "EXPORT")
                {
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblRemark"));
                }
                if (((Label) e.Row.FindControl("lblQTY")) != null)
                {
                    this.TotalQty += decimal.Parse((((Label) e.Row.FindControl("lblQTY")).Text != "") ? ((Label) e.Row.FindControl("lblQTY")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblUnitPrice")) != null)
                {
                    this.TotalPrice += decimal.Parse((((Label) e.Row.FindControl("lblUnitPrice")).Text != "") ? ((Label) e.Row.FindControl("lblUnitPrice")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblExtendedPrice")) != null)
                {
                    this.TotalExtendedPrice += decimal.Parse((((Label) e.Row.FindControl("lblExtendedPrice")).Text != "") ? ((Label) e.Row.FindControl("lblExtendedPrice")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblGrossWgt")) != null)
                {
                    this.TotalGrossWgt += decimal.Parse((((Label) e.Row.FindControl("lblGrossWgt")).Text != "") ? ((Label) e.Row.FindControl("lblGrossWgt")).Text : "0");
                }
                if (((Label) e.Row.FindControl("lblCube")) != null)
                {
                    this.TotalCube += decimal.Parse((((Label) e.Row.FindControl("lblCube")).Text != "") ? ((Label) e.Row.FindControl("lblCube")).Text : "0");
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                this.lblTotalQtyText.Text = base.GetPreferenceDigit(this.TotalQty);
                this.lblTotalPriceText.Text = base.GetPreferenceDigit(this.TotalPrice);
                this.lblTotalExtendedPriceText.Text = base.GetPreferenceDigit(this.TotalExtendedPrice);
                this.lblTotalGrossWgtText.Text = base.GetPreferenceDigit(this.TotalGrossWgt);
                this.lblTotalCubeText.Text = base.GetPreferenceDigit(this.TotalCube);
            }
        }

        protected void gvOnTheWayOrderRpt_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                OnTheWayOrderRptQueryEntity onTheWayOrderRptQueryEntity = this.GetOnTheWayOrderRptQueryEntity();
                onTheWayOrderRptQueryEntity.SortField = e.SortExpression;
                if (onTheWayOrderRptQueryEntity.SortDirection == "ASC")
                {
                    onTheWayOrderRptQueryEntity.SortDirection = "DESC";
                }
                else if (onTheWayOrderRptQueryEntity.SortDirection == "DESC")
                {
                    onTheWayOrderRptQueryEntity.SortDirection = "ASC";
                }
                this.BindData2gvInOutStockList(onTheWayOrderRptQueryEntity);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            OnTheWayOrderRptQueryEntity onTheWayOrderRptQueryEntity = new OnTheWayOrderRptQueryEntity();
            if (string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                if (this.PreviousPage != null)
                {
                    onTheWayOrderRptQueryEntity.PO_ID = this.PreviousPage.PoID;
                    onTheWayOrderRptQueryEntity.PO_DATE = this.PreviousPage.PoDate;
                    onTheWayOrderRptQueryEntity.EXTERNAL_PO_ID = this.PreviousPage.ExternalPoID;
                    onTheWayOrderRptQueryEntity.OWNER_ID = this.PreviousPage.OwnerID;
                    onTheWayOrderRptQueryEntity.VENDOR_ID = this.PreviousPage.VendorID;
                    onTheWayOrderRptQueryEntity.SKU_CLASS_ID = this.PreviousPage.SkuClassID;
                    onTheWayOrderRptQueryEntity.SKU_ID = this.PreviousPage.SkuID;
                    onTheWayOrderRptQueryEntity.PO_DATE = this.PreviousPage.PoDate;
                }
                else
                {
                    onTheWayOrderRptQueryEntity.PO_ID = "";
                    onTheWayOrderRptQueryEntity.PO_DATE = "";
                    onTheWayOrderRptQueryEntity.EXTERNAL_PO_ID = "";
                    onTheWayOrderRptQueryEntity.OWNER_ID = "";
                    onTheWayOrderRptQueryEntity.VENDOR_ID = "";
                    onTheWayOrderRptQueryEntity.SKU_CLASS_ID = "";
                    onTheWayOrderRptQueryEntity.SKU_ID = "";
                    onTheWayOrderRptQueryEntity.PO_DATE = "";
                }
            }
            else
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            onTheWayOrderRptQueryEntity.PageSize = this.gvOnTheWayOrderRpt.PageSize.ToString();
            this.PagerFooter.PageSize = this.gvOnTheWayOrderRpt.PageSize;
            onTheWayOrderRptQueryEntity.IsGetAll = false;
            onTheWayOrderRptQueryEntity.CurrentPage = "0";
            onTheWayOrderRptQueryEntity.SortField = "PO_ID,SKU_ID";
            onTheWayOrderRptQueryEntity.SortDirection = "ASC";
            this.SetOnTheWayOrderRptQueryEntity(onTheWayOrderRptQueryEntity);
            this.BindData2gvInOutStockList(onTheWayOrderRptQueryEntity);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                base.InitAnalyticsReportGridview(this.gvOnTheWayOrderRpt);
                this.LoadData();
            }
        }

        public void SetOnTheWayOrderRptQueryEntity(OnTheWayOrderRptQueryEntity onTheWayOrderRptQueryEntity)
        {
            base.PageQueryEntitySession = onTheWayOrderRptQueryEntity;
        }

        public OnTheWayOrderRptQuery PreviousPage
        {
            get
            {
                return (OnTheWayOrderRptQuery) base.PreviousPage;
            }
        }
    }
}

